package cn.lili.controller.feign;

import cn.lili.modules.statistics.client.MemberStatisticsDataClient;
import cn.lili.modules.statistics.entity.dos.MemberStatisticsData;
import cn.lili.modules.statistics.service.MemberStatisticsDataService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author paulG
 * @since 2022/1/14
 **/
@RestController
@RequiredArgsConstructor
public class MemberStatisticsDataFeignController implements MemberStatisticsDataClient {

    private final MemberStatisticsDataService memberStatisticsService;

    @Override
    public boolean addMemberStatistics(MemberStatisticsData memberStatisticsData) {
        LambdaQueryWrapper<MemberStatisticsData> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(MemberStatisticsData::getCreateDate, memberStatisticsData.getCreateDate());
        if (memberStatisticsService.count(queryWrapper) > 0) {
            return true;
        }
        return memberStatisticsService.save(memberStatisticsData);
    }
}
